import javax.swing.*;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.*;
import javax.swing.text.*;

public abstract class Components
{
    public static JLabel getLabel(String title)
    {
        JLabel label = new JLabel(title,SwingConstants.RIGHT);
        label.setFont(
            Resources.getFont(Resources.FONT_TYPE.LABELS));
        return label;
    }
    public static JLabel getLabel(String title,int orientation)
    {
        JLabel label = new JLabel(title,orientation);
        label.setFont(
            Resources.getFont(Resources.FONT_TYPE.LABELS));
        return label;
    }
    public static JLabel getLabel(String title,Resources.FONT_TYPE type)
    {
        JLabel label = new JLabel(title);
        label.setFont(
            Resources.getFont(type));
        return label;
    }
    public static JTextPane getTextPane()
    {
    	JTextPane textPane = new JTextPane();
    	textPane.setStyledDocument(
                new DefaultStyledDocument());
    	return textPane; 
    }
    public static JTextArea getTextArea()
    {
        JTextArea textArea = new JTextArea(new PlainDocument(),"",5,15);
        textArea.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
        return textArea;
    	 
    }
    public static JTextField getTextField()
    {
        final JTextField textField = new JTextField(10);
        textField.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
        textField.addFocusListener(new 
			FocusListener()
        	{
				public void focusGained(FocusEvent e) 
				{
					textField.selectAll();
				}
				public void focusLost(FocusEvent e) {}
        	}
        );
        return textField;
    }
    public static JTextField getTextField(boolean isEditable)
    {
        final JTextField textField = new JTextField(10);
        textField.addFocusListener(new 
			FocusListener()
        	{
				public void focusGained(FocusEvent e) 
				{
					textField.selectAll();
				}
				public void focusLost(FocusEvent e) {}
        	}
        );
        textField.setEditable(isEditable);
        textField.setFocusable(isEditable);
        textField.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
        return textField;
    }
    public static JTextField getTextField(int widthField)
    {
        final JTextField textField = new JTextField(widthField);
        textField.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
        textField.addFocusListener(new 
			FocusListener()
        	{
				public void focusGained(FocusEvent e) 
				{
					textField.selectAll();
				}
				public void focusLost(FocusEvent e) {}
        	}
        );
        return textField;
    }
    public static JFormattedTextField getFormattedTextField(Format format)
    {
        final MyFormattedTextField textField = new MyFormattedTextField(format);
        textField.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
        if(format instanceof NumberFormat)
        	textField.setValue(0);
        return textField;
    }
    public static JComboBox getComboBox(Object[] list)
    {
    	JComboBox combo = new JComboBox(list);
    	combo.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
    	return combo;
    }
    public static JComboBox getComboBox()
    {
    	JComboBox combo = new JComboBox();
    	combo.setFont(Resources.getFont(Resources.FONT_TYPE.FIELDS));
    	return combo;
    }
    private static class MyFormattedTextField extends JFormattedTextField
    {
    	public MyFormattedTextField(Format format)
    	{
    		super(format);
    	}
    	protected void processFocusEvent(FocusEvent e) 
        {
            super.processFocusEvent(e);
            if ( e.getID() == FocusEvent.FOCUS_GAINED )        
            	selectAll() ;
        }
    }
}
